const DB = require('../../utils/db');
module.exports = {
	list: async (pageNum, pageSize) => {
		let [all] = await DB.query(`select count(1) total from t_hole`);

		let sql = `select *,  date_format(createTime,'%Y-%m-%d ') createTime from t_hole where status=1 limit ?,?`;
		let arr = [(pageNum - 1) * pageSize, pageSize];

		let [list] = await DB.query(sql, arr);
		return { data: list, total: all[0].total };
	},
	add: async (content, name, email) => {
		let sql = '',
			arr = [];
		if (!name) {
			sql = `insert into t_hole(content,email) values(?,?)`;
			arr = [content, email];
		} else {
			sql = `insert into t_hole(content,name,email) values(?,?,?)`;
			arr = [content, name, email];
		}

		await DB.query(sql, arr);
		return true;
	}
};
